<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/images/icon.png">

    <title>河海健康系统管理版</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="/dashboard.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css"
          rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">河海健康管理系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/admin">图表</a></li>
                <li><a href="#">设置</a></li>
                <li><a href="/admin/checkApply">审批申请</a></li>
                <li><a href="/logout">注销</a></li>
            </ul>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="/admin">概况</a></li>
                <li><a href="/healthAnalyse">健康分析</a></li>
                <li><a href="/labManage">实验室管理</a></li>
                <li class="active"><a href="/admin/checkApply">账号审批<span class="sr-only">(current)</span></a></li>
                <li><a href="/authority">权限管理</a></li>
                <li><a href="/admin/personal">个人中心</a></li>
                <li><a href="/QRCode">二维码生成</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h1  class="lead" style="font-size: 25px">申请列表</h1>

            <div class="container text-center">
                <h2 class="lead" th:if="${applies.size()==0}">暂时没有账号申请哦<br>
                    <small>Have a nice day</small>
                </h2>
            </div>
            <div th:if="${applies.size()!=0}" class="">
                <table class="table table-bordered table-cell table-responsive" style="background-color: #ffffff">
                    <thead>
                    <tr>
                        <th style="background-color: #ced6e0">学号</th>
                        <th style="background-color: #ced6e0">姓名</th>
                        <th style="background-color: #ced6e0">联系方式</th>
                        <th style="background-color: #ced6e0">邮箱</th>
                        <th style="background-color: #ced6e0">实验室</th>
                        <th style="background-color: #ced6e0">宿舍</th>
                        <th style="background-color: #ced6e0"></th>
                        <th style="background-color: #ced6e0"></th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="stu:${applies}">
                        <td th:text="${stu.id}"></td>
                        <td th:text="${stu.name}"></td>
                        <td th:text="${stu.phone}"></td>
                        <td th:text="${stu.email}"></td>
                        <td th:text="${stu.labid}"></td>
                        <td th:text="${stu.dormitory}"></td>
                        <td>
                            <button onclick="commit(this)" class="btn bg-success">激活</button>
                        </td>
                        <td>
                            <button onclick="commit(this)" class="btn bg-danger">删除</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <nav  aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a th:if="${pre - 1 < 0}" class="disabled"
                               aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                            <a th:if="${pre>0}" th:href="@{/admin/checkApply(index=${pre})}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li th:if="${pre - 2 >0}"><a th:text="${pre - 2}"
                                                     th:href="@{/admin/checkApply(index=${pre - 2})}"></a></li>
                        <li th:if="${pre - 1 >0}"><a th:text="${pre -1 }"
                                                     th:href="@{/admin/checkApply(index=${pre - 1})}"></a></li>
                        <li th:if="${pre>0}"><a th:text="${pre}" th:href="@{/admin/checkApply(index=${pre})}"></a></li>
                        <li class="active"><a th:text="${current}" href="#"></a></li>
                        <li th:if="${next<=total && next>current}"><a th:text="${next}"
                                                                      th:href="@{/admin/checkApply(index=${next})}"></a>
                        </li>
                        <li th:if="${next<=total - 1 && next>current}"><a th:text="${next+1}"
                                                                          th:href="@{/admin/checkApply(index=${next+1})}"></a>
                        </li>
                        <li th:if="${next<=total - 2 && next>current}"><a th:text="${next+2}"
                                                                          th:href="@{/admin/checkApply(index=${next+2})}"></a>
                        </li>
                        <li>
                            <a th:if="${next<current}" class="disabled"
                               aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                            <a th:if="${next<=total && next>current}" th:href="@{/admin/checkApply(index=${next})}"
                               aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>
</body>

<script src="/js/echarts.min.js"></script>
<script>
    function commit(button) {
        var flag = ($(button).text());
        var td = ($(button).parent().siblings());
        var id = ($(td[0]).text());
        var email = $(td[3]).text();
        var labid = $(td[4]).text();
        var data = null;
        if (flag == "删除") {
            data = {id: id, email: email, labid: labid, enable: 0};
        } else if (flag == "激活") {
            data = {id: id, email: email, labid: labid, enable: 1};
        }
        $.ajax({
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            url: "/admin/handleApply",
            data: JSON.stringify(data),
            success: function (result) {
                console.log("success");
                if (result.responseText == "/admin/checkApply") {
                    window.location.replace(result.responseText);
                }

            },
            error: function (result) {
                var url = (result.responseText);
                if (url == "该实验室已满,激活失败") {
                    alert(url);
                } else {
                    if (url.length > 0 && url.toString() == "/admin/checkApply") {
                        window.location.replace(url);
                    } else {
                        $(button).parent().parent().remove();
                    }
                }
            }
        });
    }
</script>

</html>

